#!/bin/sh

#
# Test writing to a 5 GB offset. This test shouldn't require
# 5 GB of disk space to run, since the file should be sparse.
# This tests whether basic large file support is enabled
# internally.
#

. "$(cd "$(dirname "$0")" && pwd)/common.sh"

# Skip this test on systems that don't support sparse files (check for
# at least 1 MB hole size support)
if ! $FWUP_CREATE --sparse-check "$WORK/sparse.bin" --sparse-check-size 0x100000; then
    echo "Skipping test since OS or filesystem lacks sparse file support"
    exit 77
fi

cat >$CONFIG <<EOF
file-resource subdir/TEST {
	host-path = "${TESTFILE_150K}"
}

task complete {
	on-resource subdir/TEST { raw_write(10485760) }
}
EOF

# Create the firmware file, then "burn it"
$FWUP_CREATE -c -f $CONFIG -o $FWFILE
$FWUP_APPLY -a -d $IMGFILE -i $FWFILE -t complete

# Check that the test file got put at the right location
cmp_bytes 150000 $TESTFILE_150K $IMGFILE 0 5368709120

# Check that the verify logic works on this file
$FWUP_VERIFY -V -i $FWFILE
